package com.kaifamiao.servlet;

import com.kaifamiao.entity.User;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

@WebServlet("/user/logout")
public class UserLogoutServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {

        final String url = request.getContextPath() + "/user.jsp";

        HttpSession session = request.getSession();
        // 将登录时设置到会话中的属性移除
        session.removeAttribute("user");

        response.sendRedirect(url);
    }

}
